from time import sleep

from selenium import webdriver
# 实现规避检测
# 实现无可视化界面
from selenium.webdriver.chrome.options import Options
# 实现无可视化界面的操作
from selenium.webdriver.chrome.service import Service

chrome_options = Options()
chrome_options.add_argument('--headless')
chrome_options.add_argument('--disable-gpu')

# 实现规避检测
# option = ChromeOptions()
chrome_options.add_experimental_option('excludeSwitches', ['enable-automation'])

# 如何实现让selenium规避被检测到的风险
s = Service(r"./chromedriver.exe")
bro = webdriver.Chrome(service=s, options=chrome_options)

# 无可视化界面（无头浏览器） phantomJs
bro.get('https://www.baidu.com')

print(bro.page_source)
sleep(2)
bro.quit()
